import * as echarts from "echarts";

/**
 * @description: 生成ec图表配置信息
 * @author: 王琛
 * @Date: 2022-11-25 15:29:43
 * @param {*}
 * @return {*}
 */
export function getOptions({xAxis = {}, series = []} = {}) {
    let options = {
        tooltip: {
            trigger: "axis",
            axisPointer: {
                type: "line",
                label: {
                    backgroundColor: "#FFF",
                },
            },
        },
        legend: {
            itemWidth: 16, // 设置宽度
            itemHeight: 8, // 设置高度
            top: "2%",
            right: "0%",
            itemGap: 16,
            textStyle: {
                color: '#FFF'
            }
        },
        grid: {
            top: 30,
            left: "0%",
            right: "0%",
            bottom: 10,
            containLabel: true,
        },
        xAxis: [
            {
                type: "category",
                data: xAxis.data,
                axisLabel: {
                    textStyle: {
                        color: "#fff",
                    },
                    borderType: "dotted"
                },
                axisLine: {

                    lineStyle: {
                        color: "#fff"
                    }
                },
                axisTick: {
                    show: false,
                },
            },
        ],
        yAxis: [
            {
                type: "value",
                axisLabel: {
                    textStyle: {
                        color: "#fff",
                    },
                },
                splitLine: {
                    lineStyle: {
                        type: "dotted"
                    },
                },
                axisLine: {
                    lineStyle: {
                        color: "#fff"
                    }

                },
            },
        ],
        series: series.map((series_item) => getEcSeries(series_item)),
    }
    return options;
}

/**
 * @description: 获取当前折线图的 series 对象
 * @author: 王琛
 * @Date: 2022-11-25 16:18:34
 * @param {*}
 * @return {*}
 */
export function getEcSeries({name = "--", data = [], areaColor = "66, 133, 244",} = {}) {
    return {
        name: name,
        type: "line",
        smooth: true,
        lineStyle: {
            width: 2,
            color: `rgba(${areaColor},1)`
        },
        showSymbol: true,
        symbolSize: 6,
        symbol: "circle",
        areaStyle: {
            opacity: 1,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                    offset: 0,
                    color: `rgba(${areaColor},.2)`,
                },
                {
                    offset: 1,
                    color: `rgba(${areaColor},.0)`,
                },
            ]),
        },
        label: {
            show: true,
            color: "#fff",
            textBorderColor: "transparent"
        },
        itemStyle: {
            color: `rgba(${areaColor}.1)`
        },
        emphasis: {
            focus: "series",
        },
        data
    }
}


